package com.cqhfan.mq.config;

import com.cqhfan.mq.strategy.MqMessageHelper;
import com.cqhfan.mq.strategy.RocketMqMessageHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.apache.rocketmq.spring.support.RocketMQMessageConverter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 眭传洪
 * @create 2025-08-06 17:48
 */
@Slf4j
@Configuration
@ConditionalOnClass(RocketMQTemplate.class)
@ConditionalOnProperty(prefix = "douyin.mq", value = "enabled")
public class RocketMqConfig {

    @Bean
    @ConditionalOnClass(RocketMQTemplate.class)
    public RocketMQMessageConverter rocketMQMessageConverter() {
        // RocketMQ的消息转换器配置
        return new RocketMQMessageConverter();
    }

    @Bean
    public MqMessageHelper mqMessageHelper(RocketMQTemplate rocketMQTemplate) {
        log.info("rocketmq初始化中。。。");
        MqMessageHelper mqMessageHelper = new RocketMqMessageHelper(rocketMQTemplate);
        log.info("rocketmq初始化完成。。。");
        return mqMessageHelper;
    }

}
